package com.pro.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pro.dao.impl.MessageDaoImpl;
import com.pro.entity.MessageEntity;
import com.pro.util.BaseServlet;

/**
 * Servlet implementation class MessageServlet
 */
public class MessageServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	MessageDaoImpl messageDaoImpl = new MessageDaoImpl();
       
	public void messageAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		Date date = new Date();
		String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		String name=request.getParameter("name");
		String phone=request.getParameter("phone");
		String email=request.getParameter("email");
		String content=request.getParameter("content");
		int result=messageDaoImpl.messageAdd(new MessageEntity(0, createTime, name, phone, email, content));
		if (result>0) {
			request.getRequestDispatcher("contact.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("message.jsp").forward(request, response);
		}
	}
}
